package com.zjun.controller;

import com.zjun.pojo.MainDataPO;
import com.zjun.pojo.Result;
import com.zjun.service.impl.BackendDataServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class BackendDataController {


    @Autowired
    BackendDataServiceImpl backendDataServiceImpl;

    //获取所有数据
    @GetMapping("/getdata")
    Result GetAllData() {
        List<MainDataPO> mainDataPOList = backendDataServiceImpl.selectAllData();
        return new Result(1, "success", mainDataPOList);
    }

    //获取表单中所有的可选项
    @GetMapping("/getformoptions")
    Result GetFormOptions() {
        return backendDataServiceImpl.getFormOptions();
    }


    //新增数据记录
    @PostMapping("/insertdata")
    Result InsertData(@RequestBody Map<String, String> addForm) {
        String costType = addForm.get("costType");
        String costDetail = addForm.get("costDetail");
        String costPrice = addForm.get("costPrice");
        return backendDataServiceImpl.insertData(costType,costDetail,costPrice);
    }


}
